package com.jinglu.cloud.common.model.enums;

import java.util.*;

/**
 * 枚举基类
 * @Author lvzhenzhao
 * @Datetime 2021/03/02-下午2:27
 **/
public interface BaseEnum {

    //实现了BaseEnum的枚举Class
    Set<Class<? extends BaseEnum>> list = new LinkedHashSet<>();

    String getCode();

    String getName();

    /**
     * 获取所有实现了BaseEnum枚举的code和name键值对
     * @return
     * @author lvzhenzhao
     * @date 2021-02-12
     **/
    public static Map getListMap() {
        Map map = new LinkedHashMap();
        for (Class<? extends BaseEnum> aClass : list) {
            List<Map<String, String>> enumList = new LinkedList<Map<String, String>>();
            for (BaseEnum en : aClass.getEnumConstants()) {
                Map<String, String> e = new LinkedHashMap<String, String>();
                e.put("code", en.getCode());
                e.put("name", en.getName());
                enumList.add(e);
            }
            map.put(aClass.getSimpleName(), enumList);
        }
        return map;
    }

}
